package com.elong.businesstravel.protocol.hotel;

import java.io.File;

import org.apache.http.Header;
import org.json.JSONArray;
import org.json.JSONObject;

import android.os.Environment;

import com.android.support.jhf.utils.FileUtils;
import com.elong.businesstravel.entitys.Hotel;
import com.elong.businesstravel.entitys.HotelDocs;
import com.elong.businesstravel.protocol.baseresponse.BaseELongJsonHttpResponse;

public class GetHotelListResponse extends BaseELongJsonHttpResponse {

	public Hotel hotel = new Hotel();
	
	@Override
	public void onSuccess(int statusCode, Header[] headers,
			JSONObject mainJsonObject) throws Throwable {
		
		JSONObject responseJsonObject = mainJsonObject.getJSONObject("response");
		hotel.pageCount = responseJsonObject.optString("pageCount", "");
		hotel.lng = responseJsonObject.optString("lng", "");
		hotel.start = responseJsonObject.optString("start", "");
		hotel.lat = responseJsonObject.optString("lat", "");
		hotel.numFound = responseJsonObject.optString("numFound", "");
		hotel.prehotel = responseJsonObject.optString("prehotel");
		JSONArray docsJsonArray = responseJsonObject.getJSONArray("docs");
		for (int i = 0; i < docsJsonArray.length(); i++) {
			HotelDocs hotelDocs = new HotelDocs();
			JSONObject itemJsonObject = docsJsonArray.getJSONObject(i);
			hotelDocs.phone = itemJsonObject.optString("phone", "");
			hotelDocs.latlng_0_coordinate = itemJsonObject.optString("latlng_0_coordinate", "");
			hotelDocs.latlng_1_coordinate = itemJsonObject.optString("latlng_1_coordinate", "");
			hotelDocs.cityId = itemJsonObject.optString("cityId", "");
			hotelDocs.roomId = itemJsonObject.optString("roomId", "");
			hotelDocs.hotelId = itemJsonObject.optString("hotelId", "");
			hotelDocs.bussName = itemJsonObject.optString("bussName", "");
			hotelDocs.id = itemJsonObject.optString("id", "");
			hotelDocs.chainId = itemJsonObject.optString("chainId", "");
			hotelDocs.hotelAddress = itemJsonObject.optString("hotelAddress", "");
			hotelDocs.districtId = itemJsonObject.optString("districtId", "");
			hotelDocs.pariseScore = itemJsonObject.optString("pariseScore", "");
			hotelDocs.economicChain = itemJsonObject.optString("economicChain", "");
			hotelDocs.hotelName = itemJsonObject.optString("hotelName", "");
			hotelDocs.saleCount = itemJsonObject.optString("saleCount", "");
			hotelDocs.facilities = itemJsonObject.optString("facilities", "");
			hotelDocs.product = itemJsonObject.optString("product", "");
			hotelDocs.groupId = itemJsonObject.optString("groupId", "");
			hotelDocs.districtName = itemJsonObject.optString("districtName", "");
			hotelDocs.realStar = itemJsonObject.optString("realStar", "");
			hotelDocs.canBack = itemJsonObject.optString("canBack", "");
			String latlng = itemJsonObject.optString("latlng", "");
			if("".equals(latlng)){
				hotelDocs.latlng = new String[]{};
			}else {
				hotelDocs.latlng = latlng.split(",");
			}
			hotelDocs.bonus = itemJsonObject.optString("bonus", "");
			String manfangdays = itemJsonObject.optString("manfangdays", "");
			if("".equals(manfangdays)){
				hotelDocs.manfangdays = new String[]{};
			}else {
				hotelDocs.manfangdays = manfangdays.split(",");
			}
			hotelDocs.hotelStar = itemJsonObject.optString("hotelStar", "");
			hotelDocs.saledays = itemJsonObject.optString("saledays", "");
			hotelDocs.bussId = itemJsonObject.optString("bussId", "");
			hotelDocs.mPrepay = itemJsonObject.optString("mPrepay", "");
			hotelDocs.minPrice = itemJsonObject.optString("minPrice", "");
			hotelDocs.distance = itemJsonObject.optString("distance", "");
			hotelDocs.roomstatus = itemJsonObject.optString("roomstatus", "");
			hotelDocs.deduction = itemJsonObject.optString("deduction", "");
			
			hotel.mHotelDocs.add(hotelDocs);
		}
	}

}
